﻿@model  Model.SysMenuInfo
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Main.cshtml";
}
<script src="@Url.Content("~/Res/easyui/easyloader.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {

        $('#flexigridData').treegrid({
            title: '菜单管理',
            iconCls: 'icon-save',
            url: '/SysMenu/GetAllMetadata',
            idField: 'Id',
            treeField: 'Name',
            rownumbers: true,
            width: 650,
            toolbar: [{
                text: '选择',
                iconCls: 'icon-add',
                handler: function () {
                    flexiSelect();
                }
            }, {
                text: '添加',
                iconCls: 'icon-add',
                handler: function () {
                    flexiCreate();
                }
            }, {
                text: '修改',
                iconCls: 'icon-edit',
                handler: function () {
                    flexiModify();
                }
            }, {
                text: '删除',
                iconCls: 'icon-remove',
                handler: function () {
                    flexiDelete();
                }
            }],

            columns: [[
                    	{ field: 'Name', title: '名称', width: 215 }
					, { field: 'Url', title: '网址', width: 215 }
					, { field: 'Sort', title: '排序', width: 84 }
				    ]]
        }); 
    });

    function flexiSelect() {
        var node = $('#flexigridData').treegrid('getSelected');
        if (!node) {
            $.messager.alert('操作提示', '请选择一条数据!', 'warning');
            return false;
        }
        var arr = new Array(0);
        arr.push(node.Id);
        arr.push("^"); //主键列和显示列的分割符 ^ 
        arr.push(node.Name);
        //主键列和显示列之间用 ^ 分割   每一项用 , 分割
        if (arr.length == 3) {//一条数据和多于一条
            returnParent(arr.join("&")); //每一项用 & 分割
        }
        return false;
    }
    //导航到查看详细的按钮
    function getView() {

        var arr = $('#flexigridData').treegrid('getSelected');

        if (arr) {
            window.location.href = "../SysMenu/Details/" + arr.Id;

        } else {
            $.messager.alert('操作提示', '请选择一条数据!', 'warning');
        }
        return false;
    }
    //导航到创建的按钮
    function flexiCreate() {

        window.location.href = "../SysMenu/Edit";
        return false;
    }
    //导航到修改的按钮
    function flexiModify() {

        var arr = $('#flexigridData').treegrid('getSelected');

        if (arr) {
            window.location.href = "../SysMenu/Edit/" + arr.Id;

        } else {
            $.messager.alert('操作提示', '请选择一条数据!', 'warning');
        }
        return false;
    };
    //删除的按钮
    function flexiDelete() {

        var node = $('#flexigridData').treegrid('getSelected');
        if (!node) {
            $.messager.alert('操作提示', '请选择数据!', 'warning');

        } else {
            $.messager.confirm('操作提示', "确认删除这1项吗？", function (r) {
                if (r) {
                    $.post("/SysMenu/Delete", { query: node.Id }, function (res) {
                        if (res == "OK") {
                            remove();
                            $.messager.alert('操作提示', '删除成功!', 'info');
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '删除失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');
                            }
                        }
                    });
                }
            });
        }
        return false;
    };


    function remove() {
        var node = $('#flexigridData').treegrid('getSelected');
        if (node) {
            $('#flexigridData').treegrid('remove', node.Id);
        }
    }
</script>
@Html.Hidden("keyword", null, new { title = "关键字" })
<div style="margin: 5px;">
    <table id="flexigridData">
    </table>
</div>
<div id="dialo" title="操作">
</div>
